package net.zjitc;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Enumeration;

/**
 * Created by Administrator on 2017/9/27.
 */
@WebServlet(name = "RequestServlet",urlPatterns = "/requestServlet")
public class RequestServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    response.setContentType("text/html;charset=utf-8");
    String value=request.getHeader("User-Agent");
        PrintWriter out=response.getWriter();
        out.write(value);
        out.write("<br/>");
        Enumeration enumeration=request.getHeaderNames();
        while(enumeration.hasMoreElements())
        {
      String name= (String) enumeration.nextElement();
      String values=request.getHeader(name);
      out.write(name);
      out.write(values);
      out.write("<br/>");

      out.write("<br/>---------------------<br/>");
      String a=request.getServerName();
      out.write("服务器名"+a);
      out.write("<br/>");
            int a1=request.getServerPort();
            out.write("端口名"+a1);
            out.write("<br/>");
            String a2=request.getRequestURI();
            out.write("请求地址"+a2);
            out.write("<br/>");
        }
    }
}
